<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<form id="form" action="http://localhost:3000" method="post" enctype="multipart/form-data">
			<input type="text" name="username">
			<input type="password" name="pass">
			<input type="file" name="file">
			<button type="button" id="btn">提交</button>
		</form>
	</body>
	<script src="./xhr2.0.js"></script>
	<script>
		window.onload=function() {
			let form=document.querySelector("#form");
			let btn=document.querySelector("#btn");
			btn.addEventListener('click', async function() {
				let formdata=new FormData(form);
				let data={};
				formdata.forEach((value, key)=>{
					data[key]=value;
				});

				try {
					let res=await ajax({
						method: 'post',
						body: data,
						url: 'http://localhost:3000/',
					});
					console.log(res);
				} catch(error) {
					console.log(error);
				}
				
			})
		};
	</script>
</html>
